#include "UserSettings.h"
#include <gloox/clientbase.h>

#include <qapplication.h>

namespace gloox
{
    const std::string XMLNS_USER_SETTING = "google:setting";
    
    UserSettingsIq::UserSettingsIq(ClientBase * p)
	: m_parent(p)
    {
	qDebug("UserSettingsIq()");
	if (m_parent)
	{
	    m_parent->registerIqHandler(this, XMLNS_USER_SETTING);
	    m_parent->disco()->addFeature(XMLNS_USER_SETTING);
	}	
    }
	
    UserSettingsIq::~UserSettingsIq()
    {
	qDebug("~UserSettingsIq()");
	if (m_parent)
	{
	    m_parent->disco()->removeFeature(XMLNS_USER_SETTING);
	    m_parent->removeIqHandler(XMLNS_USER_SETTING);
	    m_parent->removeIDHandler(this);
	}
    }

    void UserSettingsIq::fetchUserSetting(UserSettingHandler *ush)
    {
	if (!m_parent || !ush)
	    return;

	//if (m_tracking)
	//    return;

	const std::string& id = m_parent->getID();
	Tag *iq = new Tag("iq");
	iq->addAttribute("type", "get");
	iq->addAttribute("id", id);
	iq->addAttribute("to", m_parent->jid().bare());
	Tag *v = new Tag(iq, "usersetting");
	v->addAttribute("xmlns", XMLNS_USER_SETTING);
	
	//m_parent->trackID(this, id, UserSettingHandler::FetchVCard);
	//m_trackMap[id] = ush;
	m_parent->send(iq);
    }
    
    
    bool UserSettingsIq::handleIq(Stanza *stanza)
    {
	qDebug(QString("handleIq:\n%1").arg(stanza->xml()));
	return true;
    }

    bool UserSettingsIq::handleIqID(Stanza *stanza, int context)
    {
	qDebug(QString("handleIqID(%1, %2)").arg("_stanza_").arg(context));
	return true;
    }
}
